<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <title>创建简单元素</title>
    <script src="jQuery-3.6.3.min.js"> </script>
    <style>
        .lei {
            color: crimson;
            background-color: chartreuse;
            font-weight: bold;
        }
    </style>
    <script>
        $(function () {

            $("#a2").click(function () {
                $("li:nth-child(odd)").toggleClass("lei");
            });
         
        })

    </script>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li id="a1">4</li>
        <li>5</li>
    </ul>
     <input id="a2" type="button" value="设置" />

   
</body>
</html>